
cc.Class({
    extends: require('Monster'),

    properties: {
        adsorb:0
    },
    onAttack(){

    },

    gameUpdate(dt){
        this._super(dt);
       var player = global.GameLoop.GameMgr.getPlayer();
        if(!player){
            return;
        }
        var selfPos = this.node.getPosition();
        /* var len = player.node.getPosition().sub(selfPos).mag()
        if(len < 400){
            var p1 = player.node.getPosition();
            var p2 = selfPos
            var len = 3
            var a = global.Common.getAngle(p1,p2);
            var ca = Math.cos(a), sa = Math.sin(a);
            var dx = ca*len*(p2.x>p1.x?1:-1)+p1.x;
            var dy = sa*len*(p2.y>p1.y?1:-1)+p1.y;
            
            player.node.x = dx;
            player.node.y = dy;
        }*/

        //吸附我方子弹
        var bullets = global.GameLoop.GameMgr.colliderMgr.getBullet(global.Enum.CAMP.friend);
        var i=0;
        while(bullets && i<bullets.length){
            var bullet = bullets[i];
            var len = bullet.node.getPosition().sub(selfPos).mag()
            if(len < this.adsorb){
                if(bullet.node.x < selfPos.x){
                    bullet.node.x += 8;
                } else {
                    bullet.node.x -= 8;
                }
            }
            i++;
        }
        
        //吸附敌方子弹
        var bullets2 = global.GameLoop.GameMgr.colliderMgr.getBullet(global.Enum.CAMP.enemy);
        var i=0;
        while(bullets2 && i<bullets2.length){
            var bullet2 = bullets2[i];
            var len = bullet2.node.getPosition().sub(selfPos).mag()
            if(len < this.adsorb){
                if(bullet2.node.x < selfPos.x){
                    bullet2.node.x += 8;
                } else {
                    bullet2.node.x -= 8;
                }
                if(len<this.adsorb/2){
                    bullet2.node.destroy()
                }
                
            }
            i++;
        }
    }

});
